package com.ityu.datastudy;

import org.springframework.util.ClassUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectUtils {
    public static Method getPrivateMethods(String className,String methodName,Class<?>... parameterTypes){
        try {
            Class<?> aClass = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
            Method declaredMethod = aClass.getDeclaredMethod(methodName, parameterTypes);
            declaredMethod.setAccessible(true);
            return declaredMethod;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Field getPrivateFiled(String className,String filedName){
        try {
            Class<?> aClass = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
            Field filed = aClass.getDeclaredField(filedName);
            filed.setAccessible(true);
            return filed;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


}
